package io.renren.modules.lucky.service.impl;

import io.renren.common.exception.RRException;
import io.renren.common.validator.Assert;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.lucky.dao.AppSysVersionDao;
import io.renren.modules.lucky.entity.AppSysVersionEntity;
import io.renren.modules.lucky.service.AppSysVersionService;

@Service("appSysVersionService")
public class AppSysVersionServiceImpl extends ServiceImpl<AppSysVersionDao, AppSysVersionEntity> implements AppSysVersionService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AppSysVersionEntity> page = this.page(
                new Query<AppSysVersionEntity>().getPage(params),
                new QueryWrapper<AppSysVersionEntity>()
        );
        return new PageUtils(page);
    }

    @Override
    public AppSysVersionEntity queryByVersionNum(String versionNum) {
        AppSysVersionEntity versionEntity = new AppSysVersionEntity();
        List<AppSysVersionEntity> list = baseMapper.selectList(new QueryWrapper<AppSysVersionEntity>()
                .eq("version_flag", 1).orderByDesc("create_time"));
        //获取最新版本
        Assert.isNull(list, "版本不存在");
        if(list.size()==0)
            throw new RRException("版本不存在");
        return list.get(0);
    }

}